package com.per.yyyFrame.common;

import com.per.yyyFrame.common.InvocationHandler;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class UReportBean {
    @Resource
    InvocationHandler invocationHandler;

    public List getMergedBillList(String dsName, String datasetName, Map<String, Object> params) throws SQLException {
        Map finalRes=new HashMap();

        List<Map> data=(List<Map>) invocationHandler.execute("select id,username,password from test where id<?",
                new ArrayList(){{add("id");add("username");add("password");}},
                new ArrayList(){{add(10);}});

        List idList=new ArrayList();
        List usernameList=new ArrayList();
        List passwordList=new ArrayList();
        data.forEach(da->{
            idList.add(da.get("id"));
            usernameList.add(new HashMap(){{put("username",da.get("username"));}});
            passwordList.add(new HashMap(){{put("password",da.get("password"));}});
        });
        finalRes.put("idList",idList);
        finalRes.put("usernameList",usernameList);
        finalRes.put("passwordList",passwordList);
        finalRes.put("dataList",data);
        finalRes.put("title","个人信息");
        finalRes.put("serialNumber","Y0001");

        return new ArrayList() {{
            add(finalRes);
        }};
    }
}
